# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>
# Maintainer (Arch Linux): Alexander Rødseth <rodseth@gmail.com>
# Contributor (Arch Linux): Angel Velasquez <angvp@archlinux.org>
# Contributor (Arch Linux): Ionut Biru  <ibiru@archlinux.ro>
# Contributor (Arch Linux): William Rea <sillywilly@gmail.com>
# Contributor (Arch Linux): Allan McRae <mcrae_allan@hotmail.com>

_realname=geany
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.24.1
pkgrel=2
pkgdesc='Fast and lightweight IDE (mingw-w64)'
arch=('any')
url='http://www.geany.org/'
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-gtk2" 
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme")
makedepends=('perlxml'
             'intltool'
             "${MINGW_PACKAGE_PREFIX}-gcc")
install=geany-${CARCH}.install
optdepends=(
            #'geany-plugins: various extra features'
            #'vte: terminal support'
            "${MINGW_PACKAGE_PREFIX}-python2")
source=(http://download.geany.org/${_realname}-${pkgver}.tar.bz2{,.sig}
        "0001-Fix-windres-invocation.patch"
        "0002-Fix-plugin-compilation.patch"
        "0003-Use-FHS.patch"
        "0004-Fix-genapi-invocation.patch")
sha256sums=('7fb505d9b01fe6874890525f837644a6a38c23a372bb068c65ef3673108a8c33'
            'SKIP'
            'aacd1815833e03ba95853f7a8adf53d848cc68f41c5cddd47f2f1a8425590a81'
            'b96b810359e45bb9a263377bc2dcca0125833bf649153cd5da24d21ee94cfb42'
            '8380b1cfa5f58233158c7e4f71d910399026df4bc3abf117087e050ecee323cf'
            'a21ff06e9022bb973f876d4edc003c23f3c244c3638281b58a2b141a6ba893b9')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Python2 fix
  sed -i '0,/on/s//on2/' data/templates/files/main.py

  # Syntax highlighting for PKGBUILD files
  sed -i 's/Sh=/Sh=PKGBUILD;/' data/filetype_extensions.conf
  
  patch -p1 -i "${srcdir}/0001-Fix-windres-invocation.patch"
  patch -p1 -i "${srcdir}/0002-Fix-plugin-compilation.patch"
  patch -p1 -i "${srcdir}/0003-Use-FHS.patch"
  patch -p1 -i "${srcdir}/0004-Fix-genapi-invocation.patch"
}

build() {
  mkdir -p "build-${MINGW_CHOST}"
  cd "build-${MINGW_CHOST}"

  # libiberty
  export LDFLAGS+=" -L${MINGW_PREFIX}/lib/binutils"

  # config.h
  export PLUGIN_CFLAGS+=" -I$(pwd)"

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX}

  make
}

package() {
  cd "build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  mkdir -p "${pkgdir}${MINGW_PREFIX}/lib/geany"
  cp plugins/*.dll "${pkgdir}${MINGW_PREFIX}/lib/geany/"
  rm -r "${pkgdir}${MINGW_PREFIX}/share/applications"
  rm -r "${pkgdir}${MINGW_PREFIX}/share/icons/hicolor/index.theme"
}
